package cn.xm.lingshi.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;

import cn.xm.lingshi.pojo.Address;
import cn.xm.lingshi.pojo.YongHu;
import cn.xm.lingshi.service.YonghuService;
import cn.xm.lingshi.service.impl.YongHuServiceImpl;

public class AddressJsonServlet extends HttpServlet {

	
	private static final long serialVersionUID = 1L;

	
	public void destroy() {
		super.destroy(); 
		
	}

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		this.doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.setContentType("text/html;charset=UTF-8");
		PrintWriter out = response.getWriter();
		// 接收请求数据
		request.setCharacterEncoding("UTF-8");
		YonghuService user=new YongHuServiceImpl();
		YongHu users=(YongHu)request.getSession().getAttribute("denglu");
		List<Address> list=null;
		if(users!=null){
			list=user.addAddress(users.getUserId());
			out.print(JSON.toJSONString(list));
		}else{
			out.print("0");
		}
		
		
		out.flush();
		out.close();
	}

	
	public void init() throws ServletException {
		
	}

}
